﻿// ==UserScript==
// @name GMaps Direction Xml
// @version v0.1
// @namespace http://code.google.com/p/m8tools
// @include http://ditu.google.cn*
// @include http://maps.google.com*
// @include http://ditu.google.com*
// ==/UserScript==

(function () {
	var xmlSpan = document.createElement("span");
	var xmlIcon = "%2F%2FIpJ9BA9ByM%2F%2F%2F%2F%2FmyguZ7M%2Ffg0H0zAtVYBP9mAOCngvDBocJQBOVeBCwAAAAAJAAOAAAEmhCJSau9%2BJ6wuv9gKIYJN54oaXZGUXRBgSxtcXSCu8SzWIKIQmMRJChqw4Wr4OApfKvOwRVkOGhLQo3phIZiMscD2xCaubKn6ktVtxjlAsHVTHtB1AKDpZ82HHRdax85DHM2WAxjDgqBMgwGBlE%2FHi0IYpaJYx2OSwUGH5QeD4wdpFekmx0OVwusr6qiKbMjCQMAuLm6u7y9vREAOw%3D%3D";
	var linkEl = document.getElementById("link");
	if (!linkEl) return;
	linkEl.addEventListener('click', function(event) {
		if (document.getElementById("panel_dir")) {
			var lateBind = function() {
				var linkDiv = document.getElementById("le").firstChild;
				linkDiv.appendChild(xmlSpan);
				xmlSpan.innerHTML = '&nbsp;&nbsp;<a target="_blank" href="#"><img src="' + xmlIcon + '"/></a>';
				xmlSpan.addEventListener('click', function(event) {
					xmlSpan.lastChild.setAttribute("href", document.getElementById("leurl").value + "&output=xml&client=maps-mwm");
				}, false);
			};
			window.setTimeout(lateBind, 500);
		}
	}, false);
})();